<template>
    <div>
      <el-table
      size='medium'
       :data="subjectarr"
      style="width: 100%">
      <el-table-column
        prop=""
        type='index'
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="subjectName"
        label="所属学科"
        width="180">
      </el-table-column>
      <el-table-column
        prop="directoryName"
        label="目录名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="username"
        label="创建者">
      </el-table-column>
      <el-table-column
        prop="addDate"
        label="创建日期">
        <template slot-scope="scope">
          <span >{{timeFn(scope.row.addDate)}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="totals"
        label="面试题数量">
      </el-table-column>
      <el-table-column
        prop="state"
        label="状态">
        <template slot-scope="scope">
          <span>{{scope.row.state? '已启用' :'已禁用'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop=""
        label="操作">
        <template slot-scope="scope">
        <el-button  type="text"  class="yi"  @click="stateFn(scope.row.id,scope.row.state)">
          <span>{{scope.row.state ? '禁用' :'启用'}}</span>
        </el-button>
        <el-button  type="text"  class="yi" @click="modifyFn(scope.row,scope.row.id)" :disabled="scope.row.state===1">修改</el-button>
        <el-button type="text"  class="yi" @click="removeFn(scope.row.id)" :disabled="scope.row.state===1">删除</el-button>
      </template>
      </el-table-column>
    </el-table>
    </div>
</template>

<script>
import moment from 'moment'
import { stateAPI } from '@/api/directorys'
export default {
  name: 'Sefrom',
  props: {
    subjectarr: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      EnableFn: false
    }
  },
  created () {
  },
  methods: {
    // 日期转换
    timeFn (time) {
      moment.locale('zh-cn')
      return moment(time).format('YYYY-MM-DD HH:mm:ss')
    },
    // 点击修改
    modifyFn (row, id) {
      this.$emit('modify', row, id)
    },
    // 点击删除
    removeFn (id) {
      this.$emit('removeFn', id)
    },
    // 刷新状态接口
    async stateFn (id, state) {
      const a = state ? 0 : 1
      console.log(a)
      await stateAPI(id, a)
      this.$message.success('操作成功')
      this.$emit('stateFn')
    }
  }
}
</script>

<style scoped>
.yi{
  font-size: 14px;
}
</style>
